package com.guigu.Curriculum.mapper;

import com.guigu.Curriculum.entity.AbCourseSort;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 课程类别 Mapper 接口
 * </p>
 *
 * @author liulinjun
 * @since 2020-07-11
 */
@Repository
public interface AbCourseSortMapper extends BaseMapper<AbCourseSort> {

    @Insert("insert into ab_course_sort VALUES(0,#{sort_title},#{sort_parent_id},null,null)")
    boolean add(@Param("sort_title") String sort_title, @Param("sort_parent_id") int id);
    @Update("update ab_course_sort set sort_title=#{sort_title },sort_parent_id=#{sort_parent_id} where sort_id=#{sort_id};")
    boolean update(@Param("sort_title") String sort_title, @Param("sort_parent_id") int sort_parent_id, @Param("sort_id") int sort_id);
    @Select("select * from ab_course_sort")
    @Results(
            @Result(column = "sort_parent_id",property = "abCourseSort",one=@One(select = "com.guigu.Curriculum.mapper.AbCourseSortMapper.ywyfindById",fetchType = FetchType.EAGER))
    )
    List<AbCourseSort> ywyfind();

    @Select("select * from ab_course_sort where sort_id=#{sort_id}")
    AbCourseSort ywyfindById(@Param("sort_id") long sort_id);
}
